package netty.inboundhandlerandoutboundhandler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * Created by yu756 on 2020/1/9 10:25
 */
public class MyByteToLongDecoder extends ByteToMessageDecoder {
    /**
     * @param channelHandlerContext 上下文
     * @param byteBuf               入站ByteBuf
     * @param list                  list 集合会将解码的数据传给下一个handler
     * @throws Exception
     */
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {

        System.out.println("MyByteToLongDecoder 被调用");
        // long 八个字节 判断需要8个字节才能读取一个long
        if (byteBuf.readableBytes() >= 8) {
            list.add(byteBuf.readLong());
        }



    }
}
